<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>JSPMyBatis的用户管理</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<h1><a href="<c:url context='${pageContext.request.contextPath}' value='/users'/>">查看所有用户</a>
</h1>
<table class="table table-striped table-responsive">
    <tr>
        <td>ID</td>
        <td>姓名</td>
        <td>密码</td>
        <td>性别</td>
        <td>出生日期</td>
        <td>注册日期</td>
    </tr>
    <c:forEach items="${requestScope.pageInfo.list}" var="user">
        <tr>
            <td>${user.id}</td>
            <td>${user.name}</td>
            <td>${user.password}</td>
            <td>${user.sex}</td>
            <td><fmt:formatDate value="${user.birthday}" pattern="yyyy年MM月dd日 HH:mm:ss"/> </td>
            <%-- 按指定的日期格式进行展示 --%>
            <td><fmt:formatDate value="${user.registTime}" pattern="yyyy年MM月dd日 HH:mm:ss"/> </td>
        </tr>
    </c:forEach>
</table>

<%-- 自己尝试:添加上一页/下一页/日期格式转换 --%>
<ul class="pagination">
    <c:if test="${requestScope.pageInfo.hasPreviousPage}">
        <li><a href="<c:url context='${pageContext.request.contextPath}' value='/users?pageNum=${requestScope.pageInfo.prePage}'/>">上一页</a></li>
    </c:if>

    <c:forEach begin="1" end="${requestScope.pageInfo.pages}" var="p">
        <li><a href="<c:url context='${pageContext.request.contextPath}' value='/users?pageNum=${p}'/>">${p}</a></li>
    </c:forEach>

    <c:if test="${requestScope.pageInfo.hasNextPage}">
        <li><a href="<c:url context='${pageContext.request.contextPath}' value='/users?pageNum=${requestScope.pageInfo.nextPage}'/>">下一页</a></li>
    </c:if>
</ul>

</body>
</html>